import math
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton,QWidget
from PyQt5.QtCore import *
from mainwindow import Ui_MainWindow
import random
import numpy as np
step=14
d_step= int(step*(math.sqrt(2)/2))
bottom=762
left_x=19
right_x=763
mid_down=394
mid_up=330
mid=362
up=58
l_state=0
r_state=1
l_actions=[7,4,9,15,12,17] #向左的动作集合
r_actions=[6,3,8,14,11,16]
attack_acts=[12,15,10,14,11,16,13,17,1] #攻击动作集合
down_attack=[10,15,14,12,11,1]
up_start_actcs=[17,13,16,1] #2号的发球动作集合
down_start_acts=[15,10,14,1] #1号的发球动作集合
sleep_time=25

HIT_RANGE=90
PLAY_1_ON=0  #轮到1号接球
PLAY_2_ON=1
P1_START=2  #1号发球
P2_START=3
NOISE=400
WEAK_RANGE=600
FREEAZ=15
move_r=0.06
sc_r=3
hit_r=0.2


UPMID=(385,214) #上半场中场位置
DOWNMID=(385,int((mid_down+bottom)/2))

def ramdom_pt(x1,y1,x2,y2):
    '''
    生成区域内的随机点
    '''
    if x1<x2:
        x=random.randint(x1,x2)
    else:
        x=random.randint(x2,x1)
    if y1<y2:
        y=random.randint(y1,y2)
    else:
        y=random.randint(y2,y1)
    
    x=x if x>left_x else left_x
    x=x if x<right_x else right_x
    y=y if y<bottom else bottom
    y=y if y>up else up
    return x,y


def get_dis(x1,y1,x2,y2):
    return math.sqrt(math.pow((x1-x2),2)+math.pow((y1-y2),2))


if __name__=='__main__':
    f=(math.sqrt(math.pow((right_x-left_x),2)+math.pow((up-mid_up),2)))/math.sqrt(math.pow((right_x-left_x),2)+math.pow((bottom-mid_down),2))
    print(f)